package com.pureut.equipment.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.equipment.domain.dto.InspectionItemDto;
import com.pureut.equipment.domain.dto.PatrolItemDto;
import com.pureut.equipment.domain.vo.InspectionItemVo;
import com.pureut.equipment.domain.vo.PatrolItemVo;
import com.pureut.equipment.service.PatrolItemService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 *
 * Author:巡检项目控制层
 * Date:2023/04/26 9:54
 * @DESC
 */
@RestController
@RequestMapping("/patrol-item")
public class PatrolItemController extends BaseController {

    /**
     * 巡检项目service
     */
    @Resource
    PatrolItemService patrolItemService;

    /**
     * 巡检项目列表
     * @param patrolItemVo
     * @return
     */
    @RequiresPermissions("device:inspection:project:list")
    @GetMapping("/list")
    public TableDataInfo list(PatrolItemVo patrolItemVo) {
        startPage();
        List<PatrolItemDto> list = patrolItemService.getList(patrolItemVo);
        return getDataTable(list);
    }

    /**
     * 新增
     */
    @RequiresPermissions("device:inspection:project:add")
    @Log(title = "新增", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody PatrolItemVo patrolItemVo) throws Exception {
        return toAjax(patrolItemService.add(patrolItemVo));
    }

    /**
     * 删除
     */
    @RequiresPermissions("device:inspection:project:remove")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("/deletePatrolItem/{id}")
    public AjaxResult deletePatrolItem(@PathVariable("id") Long id) {
        return toAjax(patrolItemService.deletePatrolItem(id));
    }

    /**
     * 修改
     */
    @RequiresPermissions("device:inspection:project:edit")
    @Log(title = "修改", businessType = BusinessType.UPDATE)
    @PutMapping("/updatePatrolItem")
    public AjaxResult updatePatrolItem(@RequestBody PatrolItemVo patrolItemVo) throws Exception {
        return toAjax(patrolItemService.updatePatrolItem(patrolItemVo));
    }

    /**
     * 查看
     */
    @RequiresPermissions("device:inspection:project:query")
    @GetMapping("/queryPatrolItem/{id}")
    public AjaxResult queryPatrolItem(@PathVariable("id") Long id) {
        return AjaxResult.success(patrolItemService.queryPatrolItem(id));
    }
}
